//
//  YDRechargeTopView.m
//  PeiZiWangBei
//
//  Created by LK-IOS on 2017/11/14.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//

#import "YDRechargeTopView.h"

@interface YDRechargeTopView()

@property (nonatomic, strong)UIImageView *bgImage;


//标题
@property (nonatomic , weak) UILabel *accountBalance;

//盈亏金额
@property (nonatomic , weak) UILabel *balanceNumber;

//标题
@property (nonatomic, strong)UILabel *titleLbl;


//返回按键
@property (nonatomic, strong)UIButton *backBtn;


@end



@implementation YDRechargeTopView

-(void)setAmountString:(NSString *)amountString
{
    _amountString = amountString;
    
    self.balanceNumber.text = amountString;
}

-(void)setTitle:(NSString *)title
{
    _title = title;
    self.titleLbl.text = title;
}


-(void)setName:(NSString *)name
{
    _name = name;
    self.accountBalance.text = name;
}
-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        [self bgImage];
        [self backBtn];
        [self titleLbl];
        [self accountBalance];
        [self balanceNumber];
        
        
        
    }
    return self;
}

+(instancetype)rechargeTopViewWithAmount:(NSString *)amountString
{
    YDRechargeTopView *topView = [[self alloc] init];
    topView.amountString = amountString;
    return topView;
}

- (void)goBack
{
    if (self.backBlock) {
        self.backBlock(YES);
    }
}


-(UIImageView *)bgImage
{
    if (_bgImage == nil) {
        _bgImage = [UIImageView new];
        [self addSubview:_bgImage];
        [_bgImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.bottom.equalTo(@0);
        }];
        _bgImage.image = [UIImage imageNamed:@"wd-wodechicang-bg"];
        
    }
    return _bgImage;
}

- (UIButton *)backBtn
{
    if (_backBtn == nil) {
        _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_backBtn setBackgroundImage:[UIImage imageNamed:@"nav-all-back"] forState:UIControlStateNormal];
        [_backBtn addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_backBtn];
        [_backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(@(rate375(19.1)));
            make.top.equalTo(isPhoneX? @(rateX812(33) + 24) : @(rate750(33)));
        }];
    }
    return _backBtn;
}

-(UILabel *)titleLbl
{
    if (_titleLbl == nil) {
        _titleLbl = [UILabel new];
        [self addSubview:_titleLbl];
        _titleLbl.font = [UIFont systemFontOfSize:20];
        _titleLbl.textAlignment = NSTextAlignmentCenter;
        [_titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self);
            make.top.equalTo(_backBtn.mas_top);
        }];
        _titleLbl.text = @"充值";
        _titleLbl.textColor = [UIColor whiteColor];
        
    }
    return _titleLbl;
}
-(UILabel *)accountBalance
{
    if (_accountBalance == nil) {
        UILabel *accountBalance = [[UILabel alloc] init];
        [self addSubview:accountBalance];
        accountBalance.textAlignment = NSTextAlignmentLeft;
        accountBalance.font = [UIFont systemFontOfSize:font14ScreenWRate * LKScreenW];
        accountBalance.textColor = [UIColor whiteColor];
       
        accountBalance.text = @"账户可用余额:";
        [accountBalance  mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(rate375(23));
            if (isPhoneX) {
                make.top.equalTo(_titleLbl.mas_bottom).offset(rateX812(22));
            }else{
                make.top.equalTo(_titleLbl.mas_bottom).offset(rate750(22));
            }
        }];
        
        _accountBalance = accountBalance;
    }
    return _accountBalance;
}


-(UILabel *)balanceNumber
{
    if (_balanceNumber == nil) {
        UILabel *balanceNumber = [[UILabel alloc] init];
        [self addSubview:balanceNumber];
        balanceNumber.textAlignment = NSTextAlignmentLeft;
    
        balanceNumber.font = [UIFont fontWithName:@"Helvetica-Bold" size:font36ScreenWRate * LKScreenW];
        balanceNumber.textColor = [UIColor whiteColor];
        balanceNumber.text = @"";
        [balanceNumber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.accountBalance);
            if (isPhoneX) {
                make.top.equalTo(self.accountBalance.mas_bottom).offset(rateX812(10));
            }else{
                make.top.equalTo(self.accountBalance.mas_bottom).offset(rate750(10));
            }
        }];
        _balanceNumber = balanceNumber;
    }
    return _balanceNumber;
}



@end
